<?php  
import('miho.router.*');
/**
* 
*/
abstract class BaseRouter
{
  protected $_map;
  
  protected $_parameters;
  
  protected $_uri;
  
  protected $_defaultAppliction = 'default';
  protected $_defaultConrtoller = 'default';
  protected $_defaultAction = 'index';
  
  public function getDefaultApplication(){
    return $this->_defaultAppliction;
  }
  
  public function setDefaultApplication($value){
    $this->_defaultAppliction = $value;
  }
    
  
  
  public function getDefaultcontoller(){
    return $this->_defaultConrtoller;
  }
  
  public function setDefaultController($value){
    $this->_defaultConrtoller = $value;
  }
  
  
  
  
  public function getDefaultAction(){
    return $this->_defaultAction;
  }
  
  public function setDefaultAction($value){
    $this->_defaultAction = $value;
  }
  
  public function __construct(){
    $this->_map = new RouterMap();
    $this->_parameters = array();
  }
  
  public function getMap(){
    return $_map;
  }
  
  public function addRoute(IRoute $route){
    $this->_map->addRoute($route);
    return $this;
  }
  
  public function getParameter($name){
    return isset($this->_parameters[$name]) ? $this->_parameters[$name] : null;
  }
  
  public function route($request){
  	$this->_uri = $request->getQuery();
    $this->_parseRequest();
    return $this;
  }
  
  public function configure($routes){

    foreach ($routes as $r) {
      $route = new PatternRoute($r->name);
      $route->setValue($r->url);
      if(isset($r->defaults)){
        foreach ($r->defaults as $key) {
          foreach($key as $prop=>$val){
            $route->setParameter($prop,$val);
          }
        }
      }
      $this->addRoute($route);
    }
  }
  
  abstract protected function _parseRequest();
}


?>